package com.ques.service.impl;

import com.ques.dao.AnswerDao;
import com.ques.entity.QueryParam;
import com.ques.pojo.QuestionAnswer;
import com.ques.service.AnswerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zq  2020-02-08
 */
@Service
public class AnswerServiceImpl implements AnswerService {

    @Autowired
    AnswerDao answerDao;


    @Override
    public boolean addQuestionAnswer(String questionId, QuestionAnswer questionAnswer) {

        boolean isInsert = answerDao.inserAnswer(questionId, questionAnswer);

        return isInsert;
    }

    @Override
    public List<QuestionAnswer> getAllAnswerPage(QueryParam queryParam) {

        if (queryParam.getPageSize() == 0) {
            queryParam.setPageSize(10);
        }
        if (queryParam.getCurrentPage() < 0) {
            queryParam.setPageSize(0);
        }
        List<QuestionAnswer> answers = answerDao.selectAllAnswerPage(queryParam);
        return answers;
    }

    @Override
    public List<QuestionAnswer> getAllAnswer(String questionId) {
        List<QuestionAnswer> answers = answerDao.selectAllAnswer(questionId);
        return answers;
    }


    @Override
    public long deleteAnswer(String quesId, List<String> answerId) {

        long count = answerDao.deleteAnswer(quesId, answerId);

        return count;
    }
}
